//
//  WBNetworkManager+Extension.swift
//  传智新浪微博
//
//  Created by app on 17/7/17.
//  Copyright © 2017年 app. All rights reserved.
//

import Foundation

// MARK: - 封装新浪微博的网络请求方法
extension WBNetworkingManager {
    
    
    /// 加载微博数据字典数组
    ///
    /// - Parameter completion: 完成回调[list: 微博字典数组/是否成功]
    func statusList(completion: @escaping (_ list: [[String: AnyObject]], _ isSuccess: Bool)->()) { // 一个中括号是字典，两个中括号是数组
        
        let urlString = "https://api.weibo.com/2/statuses/home_timeline.json"
        let params = ["access_token": "2.00DRYrNDcIHQJC0a23aa3b64n1EX8E"]

        
        request(method: .GET, URLString: urlString, parameters: params as [String : AnyObject]) {(json, isSuccess) in
            
            // 从 json 中获取 statuses 字典数组
            // 如果 as？失败，result = nil
            let result = json?["statuses"] as? [[String: AnyObject]]
            
            // 回调
            completion(result!, isSuccess)
        }

    }
}
